package onion.molingo2o.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;

import onion.molingo2o.Config;
import onion.molingo2o.R;
import onion.molingo2o.adapter.OnionAdapter;
import onion.molingo2o.bean.WonderFulRecourse;

/**
 * Created by Administrator on 2015/11/10.
 */
public class RecourseFragment extends BaseFragment {
    ListView listview;

    OnionAdapter adapter;
    ArrayList<WonderFulRecourse> wonderFulRecourses = new ArrayList<WonderFulRecourse>();
    private int bottomVisibleIndex = 0; // 屏幕中最下方一项的索引
    public int pageNumber = 0; // 请求的页码，初始为1
    public int pageSize = 15; // 一次请求的个数
    public int totalCount = 0; // 总数，在OBLCourseMainActivity中赋值
    public int gotCount = 0; // 已请求的数量，在OBLCourseMainActivity中赋值

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return View.inflate(getActivity(), R.layout.activity_recourse, null);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private void initView() {
        // TODO Auto-generated method stub
        listview = (ListView) getView()
                .findViewById(R.id.listview);
        adapter = new OnionAdapter(getActivity(), R.layout.wonderful_activity_adapter, wonderFulRecourses, new String[]{"title"}, new String[]{"getFaceImage"}, Config.adOptions);

        listview.setAdapter(adapter);
        listview.setOnItemClickListener(onItemClickListener);
        testData();
    }

    private void testData() {
        wonderFulRecourses.add(new WonderFulRecourse(0, 0, "如何使用帮帮?", "http://b.hiphotos.baidu.com/image/h%3D200/sign=234bd32e09d79123ffe093749d355917/0823dd54564e925838c205c89982d158ccbf4e26.jpg"));
        wonderFulRecourses.add(new WonderFulRecourse(0, 0, "如何使用帮帮?", "http://e.hiphotos.baidu.com/image/h%3D200/sign=721b254ed409b3def4bfe368fcbf6cd3/d1160924ab18972bf05282ece3cd7b899e510aaf.jpg"));
        wonderFulRecourses.add(new WonderFulRecourse(0, 0, "如何使用帮帮?", "http://e.hiphotos.baidu.com/image/h%3D200/sign=721b254ed409b3def4bfe368fcbf6cd3/d1160924ab18972bf05282ece3cd7b899e510aaf.jpg"));
        adapter.notifyDataSetChanged();
    }

    AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        }
    };


}
